package com.nightsoul.hadoop1.test.join;

import java.io.IOException;
import java.util.Iterator;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;

import com.nightsoul.hadoop1.test.TextPair;

/**
 * 连接已标记的气象站记录和已标记的气象记录的reducer
 * @author zj
 *
 */
public class JoinReducer extends MapReduceBase	implements	Reducer<TextPair, Text, Text, Text> {

	@Override
	public void reduce(TextPair key, Iterator<Text> values,
			OutputCollector<Text, Text> output, Reporter reporter)
			throws IOException {
				
		Text stationName = new Text(values.next());
		while(values.hasNext()) {
			Text record = values.next();
			Text outValue = new Text(stationName.toString() + "\t" + record.toString());
			output.collect(key.getFirst(), outValue);;
		}
	}

}
